package ar.com.fiuba;

import java.io.IOException;

import ar.com.fiuba.domain.CoeficientCalculationStrategy;
import ar.com.fiuba.domain.CommonCoeficientCalculationStrategy;
import ar.com.fiuba.domain.CommonCoeficientCalculationWithPositionStrategy;
import ar.com.fiuba.domain.Dictionary;
import ar.com.fiuba.domain.api.Corrector;
import ar.com.fiuba.domain.impl.DictionaryImpl;

public class QueryCorrector {

	//Invocacion modo "Test" :QueryCorrector archDiccionario longNgrama -test [loadDB]
	//Invocacion modo "Corrector" :QueryCorrector archDiccionario longNgrama -correct palabraACorregir [loadDB]

	public static void main(String[] args)
	{
		
		String filename = args[0];
		int longNGrama = Integer.valueOf(args[1]);
		String mode;
		if(args[2] != null && args[2].equals("-test")){
			mode="-test";
		}
		else{	
			if(args[2] != null && args[2].equals("-correct")){
					mode="-correct";
			}		
			else{
					System.out.println("Error en los parametros de invocacion");
					return;
			}		
		}
		Dictionary dictionary;
		if ( (mode.equals("-test") && args.length == 4 && args[3] != null && args[3].equals("loadDB")) ||
			    (mode.equals("-correct") &&  args[3] != null && args[4].equals("loadDB"))){
			dictionary = new DictionaryImpl(filename,longNGrama,true);
		}

		else{
			dictionary = new DictionaryImpl(filename,longNGrama,false);
		}
		
		CoeficientCalculationStrategy calculator;
		// cambiar la condición para usar la otra estrategia (ESPANTOSO).
		if (true)
			calculator = new CommonCoeficientCalculationStrategy();
		else
			calculator = new CommonCoeficientCalculationWithPositionStrategy();
		
		Corrector corrector = new Corrector(dictionary, calculator);
		
		if(mode.equals("-correct") && args[3] != null){
			System.out.println("Palabra ingresada: " + args[3] + " || Palabra corregida: " + corrector.getBestMatch(args[3]));
		}
		
		if(mode.equals("-test")){
			
			ReportGenerator report = new ReportGenerator(corrector,filename,20);
			try {
				report.generateReports();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	
		}
		
		
	}
		
}
